package com.htgd.gardenexpo.controller;


import com.htgd.gardenexpo.dto.GeConChallengeSportsDTO;
import com.htgd.gardenexpo.dto.GeConGoalSportsDTO;
import com.htgd.gardenexpo.entity.CommonResult;
import com.htgd.gardenexpo.service.IGeConChallengeSportsService;
import com.htgd.gardenexpo.utils.TokenUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 * 挑战跑 前端控制器
 * </p>
 *
 * @author author
 * @since 2025-04-06
 */
@RestController
@RequestMapping("/api/challengeSports")
@Api(tags = "挑战跑")
@Slf4j
public class GeConChallengeSportsController {

    @Autowired
    private IGeConChallengeSportsService geConChallengeSportsService;

    @PostMapping(value = "/add")
    @ApiOperation("添加")
    public CommonResult add(@RequestBody GeConChallengeSportsDTO geConChallengeSportsDTO, HttpServletRequest request) {
        String accessToken = request.getHeader("Access_token");
        String openId = TokenUtil.getUsernameFromToken(accessToken);
        log.info("挑战跑-添加：{}，{}",geConChallengeSportsDTO,openId);
        return geConChallengeSportsService.add(geConChallengeSportsDTO,openId);
    }

    @GetMapping(value = "/getTaskDetails")
    @ApiOperation("获取任务详情")
    public CommonResult getTaskDetails(@RequestParam(value = "taskId") String taskId) {
        log.info("挑战跑-获取任务详情：{}",taskId);
        return geConChallengeSportsService.getTaskDetails(taskId);
    }

}
